package pl.org.lutra.planner.log;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;

public class FileHandlerFactory {
    
    public static FileHandler createFileHandler(String pattern) throws IOException, SecurityException {
        if (pattern.contains(System.getProperty("file.separator"))) {
            checkIfDirectoryExists(pattern);
        }
        return new FileHandler(pattern);
    }
    
    protected static void checkIfDirectoryExists(String pattern) {
        File file = new File(pattern);
        File parent = file.getParentFile();
        
        if (!parent.exists()) {
            parent.mkdir();
        }
    }
    
}
